package com.bjpowernode.dataservice.service;

import com.bjpowernode.api.dto.ProductBidInfo;
import com.bjpowernode.api.dto.ProductCollection;
import com.bjpowernode.api.dto.ProductIncomeInfo;
import com.bjpowernode.api.model.Product;
import com.bjpowernode.api.serivce.ProductService;
import com.bjpowernode.constants.Constant;
import com.bjpowernode.dataservice.mapper.ProductMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 麦翔盛
 * @ClassName: ProductServiceImpl
 * @Package: com.bjpowernode.dataservice.service
 * @description: 产品类 逻辑 实现
 * @date 2022/5/14 21:08
 */
@Service
@DubboService(interfaceClass = ProductService.class,version = "1.0")
public class ProductServiceImpl implements ProductService {
    @Resource
    private ProductMapper productMapper;

    @Override
    public ProductCollection queryMainProductList() {
        ProductCollection productCollection = new ProductCollection();
        //查询不同产品的数据
        productCollection.setXinList(productMapper.queryProductByType(Constant.PRODUCT_TYPE_X,0,1));
        productCollection.setYouList(productMapper.queryProductByType(Constant.PRODUCT_TYPE_Y,0,3));
        productCollection.setSanList(productMapper.queryProductByType(Constant.PRODUCT_TYPE_S,0,3));
        return productCollection;
    }

    @Override
    public List<Product> queryProductByTypePage(Integer productType, Integer pageNo, Integer pageSize) {
        //计算分页数据
        int offset = (pageNo - 1) * pageSize;
        int limit = pageSize;

        //返回数据
        return productMapper.queryProductByType(productType,offset,limit);
    }

    @Override
    public Integer computerCountByType(Integer productType) {
        return productMapper.countByType(productType);
    }

    @Override
    public Product queryProductById(Integer id) {
        return productMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ProductBidInfo> queryProductBidInfoByUid(Integer uid, Integer pageNo, Integer pageSize) {
        //计算分页信息
        int limit = pageSize;
        int offset = (pageNo - 1) * limit;
        //返回分页数据
        return productMapper.selectProductBidInfoByUid(uid,offset,limit);
    }

    @Override
    public List<ProductIncomeInfo> queryProductIncomeInfoByUid(Integer uid, Integer pageNo, Integer pageSize) {
        //计算分页信息
        int limit = pageSize;
        int offset = (pageNo - 1) * limit;
        return productMapper.selectProductIncomeInfoByUid(uid,offset,limit);
    }
}
